package org.agbe;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;

public class MediaPlayerLooper implements OnCompletionListener {

	private final int maxIteration;
	private int nbOfIterationDone;

	private final MediaPlayerContext playerContext;

	public MediaPlayerLooper(Integer maxIterations,
			MediaPlayerContext playerContext) {
		this.maxIteration = maxIterations;
		this.playerContext = playerContext;
	}

	public void onCompletion(MediaPlayer mp) {
		nbOfIterationDone++;
		if (nbOfIterationDone >= maxIteration) {
			playerContext.stopSound();
		} else {
			playerContext.getPlayer().start();
		}
	}
}
